package info.yaohua.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.naming.NamingException;

import info.yaohua.data.DBHelper;
import info.yaohua.dto.Ac01Dto;
import info.yaohua.dto.Ac02Dto;
import info.yaohua.util.UtilHelper;

public class Ac01Dao {


	DBHelper dbHelper = new DBHelper();
	Vector<String> paramList ;
	
	
	/* * ����û����ѯAc01
	 * @param ac01
	 * @return
	 * @throws SQLException 
	 * @throws NamingException 
	 */
	public Ac01Dto doFindAc01ByAac001(Ac01Dto ac01) throws NamingException, SQLException  
	{
			Connection conn = dbHelper.getConnection();
			String tableName = "ac01";
			paramList = new Vector<String>();
			paramList.add("aac001");
			String sql = UtilHelper.selectSqlCreate(tableName, paramList);
			
			PreparedStatement pstmt = null;
			ResultSet rst = null;
			
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, ac01.getAac001());
			rst = pstmt.executeQuery();
			
			Ac01Dto ac01Dto =null;
			if(rst.next())
			{
				ac01Dto = new Ac01Dto();
				ac01Dto.setAac001(rst.getString("aac001"));
				ac01Dto.setAac002(rst.getString("aac002"));
				ac01Dto.setAac003(rst.getString("aac003"));
				ac01Dto.setAac004(rst.getString("aac004"));
				ac01Dto.setAac005(rst.getString("aac005"));
				ac01Dto.setAac006(rst.getString("aac006"));
				ac01Dto.setAac007(rst.getString("aac007"));
				ac01Dto.setAac008(rst.getDate("aac008"));
				ac01Dto.setAac009(rst.getString("aac009"));
				
			}
			try
			{
				rst.close();
				pstmt.close();
				conn.close();
			}
		catch (SQLException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return ac01Dto;
	}
	
	
	
	/* * ����û��������ѯAc01
	 * @param ac01
	 * @return
	 * @throws SQLException 
	 * @throws NamingException 
	 */
	public Ac01Dto doFindAc01ByAac001_Aac005(Ac01Dto ac01) throws NamingException, SQLException  
	{
		 Connection conn = dbHelper.getConnection();
			String tableName = "ac01";
			paramList = new Vector<String>();
			paramList.add("aac001");
			paramList.add("aac005");
			String sql = UtilHelper.selectSqlCreate(tableName, paramList);
			
			PreparedStatement pstmt = null;
			ResultSet rst = null;
			
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, ac01.getAac001());
			pstmt.setString(2, ac01.getAac005());
			rst = pstmt.executeQuery();
			
			Ac01Dto ac01Dto =null;
			if(rst.next())
			{
				ac01Dto = new Ac01Dto();
				ac01Dto.setAac001(rst.getString("aac001"));
				ac01Dto.setAac002(rst.getString("aac002"));
				ac01Dto.setAac003(rst.getString("aac003"));
				ac01Dto.setAac004(rst.getString("aac004"));
				ac01Dto.setAac005(rst.getString("aac005"));
				ac01Dto.setAac006(rst.getString("aac006"));
				ac01Dto.setAac007(rst.getString("aac007"));
				ac01Dto.setAac008(rst.getDate("aac008"));
				ac01Dto.setAac009(rst.getString("aac009"));
				
			}
			try
			{
				rst.close();
				pstmt.close();
				conn.close();
			}
		catch (SQLException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return ac01Dto;
	}
	
	/**
	 * insert ac01
	 * @param ac01Dto
	 * @return
	 * @throws NamingException
	 * @throws SQLException
	 */
	public int doStore(Ac01Dto ac01Dto) throws NamingException, SQLException
	{
		 Connection conn = dbHelper.getConnection();
		 String sql = UtilHelper.insertSqlCreate("ac01", 9);
		 PreparedStatement pstmt = null;
			
			
		 pstmt = conn.prepareStatement(sql);
		 pstmt.setString(1, ac01Dto.getAac001());
		 pstmt.setString(2, ac01Dto.getAac002());
		 pstmt.setString(3, ac01Dto.getAac003());
		 pstmt.setString(4, ac01Dto.getAac004());
		 pstmt.setString(5, ac01Dto.getAac005());
		 pstmt.setString(6, ac01Dto.getAac006());
		 pstmt.setString(7, ac01Dto.getAac007());
		 pstmt.setDate(8, ac01Dto.getAac008());
		 pstmt.setString(9, ac01Dto.getAac009());
		 
		 int success = pstmt.executeUpdate();
		 
		 try
			{
			//	rst.close();
				pstmt.close();
				conn.close();
			}
		catch (SQLException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return success;
		
	}

	//更新密码
	public int  doUpdateAac005ByAac001(Ac01Dto ac01Dto) throws NamingException, SQLException
	{
		Connection conn = dbHelper.getConnection();
		String sql = "update ac01 set aac005='"
				+ac01Dto.getAac005()
				+"' where aac001 = ?";
				
		
		PreparedStatement pstmt = null;
		ResultSet rst = null;
		
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, ac01Dto.getAac001());
		int success = pstmt.executeUpdate();
		
		try
		{
		//	rst.close();
			pstmt.close();
			conn.close();
		}
	catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return success;
		
	}
	
}
